<template>
  <div class="home-container">
    <!-- 导航栏 -->
    <van-nav-bar class="page-nav-bar" fixed>
      <van-button
        class="search-btn"
        slot="title"
        type="info"
        size="small"
        round
        icon="search"
        to=""
        >搜索</van-button
      >
    </van-nav-bar>
    <!-- /导航栏 -->
    <!-- 频道列表 -->
    <van-tabs class="channel-tabs" v-model="active" animated swipeable>
      <van-tab
        :title="channel.name"
        v-for="channel in channels"
        :key="channel.id"
      >
        <article-list :channel="channel" />
      </van-tab>
      <div slot="nav-right" class="placeholder"></div>
      <div slot="nav-right" class="hamburger-btn">
        <i class="toutiao toutiao-gengduo" @click="isChennlEditShow = true"></i>
      </div>
    </van-tabs>

    // 弹出层
    <van-popup
      v-model="isChennlEditShow"
      closeable
      position="bottom"
      :style="{ height: '100%' }"
      close-icon-position="top-left"
    >
      <channel-edit :my-channels="channels" :active='active' />
    </van-popup>
  </div>
</template>

<script>
import { getUserChannels } from '@/api/user'
import ArticleList from './components/article-list.vue'
import ChannelEdit from './components/channel-edit'
export default {
  name: 'HomeIndex',
  components: {
    ArticleList,
    ChannelEdit
  },
  props: {},
  data() {
    return {
      active: 0,
      channels: [],
      isChennlEditShow: false
    }
  },
  computed: {},
  watch: {},
  created() {
    this.loadChannels()
  },
  mounted() {},
  methods: {
    async loadChannels() {
      try {
        const { data } = await getUserChannels()
        this.channels = data.data.channels
      } catch (error) {
        this.$toast('获取频道数据失败了')
      }
    }
  }
}
</script>

<style scoped lang="less">
.home-container {
  padding-top: 30px;
  padding-bottom: 70px;
  /deep/.van-nav-bar__title {
    max-width: unset;
  }
  .search-btn {
    width: 180px;
    height: 44px;
    background-color: #5babfb;
    border: none;
    font-size: 28px;
    .van-icon {
      font-size: 32px;
    }
  }
}
/deep/ .channel-tabs {
  .van-tabs_wrap {
    height: 82px;
  }
  .van-tab {
    border-right: 1px soild red;
    min-width: 95px;
    height: 52px;
    color: #777777;
  }
  .van-tab--active {
    color: #333333;
  }
}
.hamburger-btn {
  position: fixed;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 46px;
  height: 52px;
  opacity: 0.902;
  i.toutiao {
    font-size: 33px;
  }
  &:before {
    content: '';
    width: 10px;
    height: 100%;
    width: 1px;
    position: absolute;
    left: 0;
    background-image: url(~@/assets/gradient-gray-line.png);
    background-size: contain;
  }
}
.placeholder {
  width: 46px;
  height: 52px;
  flex-shrink: 0;
}
.van-tabs__wrap {
  position: fixed;
  top: 92px;
  z-index: 2;
  width: 100%;
}
</style>
